﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLTV.Forms.KhaiBao
{
    public partial class frmQuanHuyen : DevExpress.XtraEditors.XtraForm
    {
        public frmQuanHuyen()
        {
            InitializeComponent();
        }

        public int QuanHuyenId
        {
            get;
            set;
        }
        public int TinhThanhID { get; set; }


        private void frmQuanHuyen_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsDiaChi.tblTinhThanh' table. You can move, or remove it, as needed.
            this.tblTinhThanhTableAdapter.Fill(this.dsDiaChi.tblTinhThanh);
            // TODO: This line of code loads data into the 'dsDiaChi.tblQuanHuyen' table. You can move, or remove it, as needed.
            this.tblQuanHuyenTableAdapter.Fill(this.dsDiaChi.tblQuanHuyen);
            if (this.QuanHuyenId != 0)
            {
                tblQuanHuyenBindingSource.MoveFirst();
                for (int i = 0; i < tblQuanHuyenBindingSource.Count; i++)
                {
                    QLTV.Database.dsDiaChi.tblQuanHuyenRow quanhuyen = (QLTV.Database.dsDiaChi.tblQuanHuyenRow)((DataRowView)tblQuanHuyenBindingSource.Current).Row;
                    if (quanhuyen.QuanHuyenID == this.QuanHuyenId)
                    {
                        break;
                    }
                    else
                    {
                        tblQuanHuyenBindingSource.MoveNext();
                    }
                }
            }
            else
            {
                tblQuanHuyenBindingSource.AddNew();
            }

            if (this.TinhThanhID != 0)
            {
                luTinhThanh.EditValue = this.TinhThanhID;
            }

        }
        void updateQuanHuyen()
        {
            if (dxValidationProvider1.Validate())
            {
                tblQuanHuyenBindingSource.EndEdit();
                tblQuanHuyenTableAdapter.Update(dsDiaChi.tblQuanHuyen);
            }

        }

        private void cmdSaveInsert_Click(object sender, EventArgs e)
        {
            updateQuanHuyen();
            tblQuanHuyenBindingSource.AddNew();
        }

        private void cmdLuuVaDong_Click(object sender, EventArgs e)
        {
            updateQuanHuyen();
            this.Close();
        }

        private void cmdDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}